package jms;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import jms.connection.JmsConnection;

public class JmsProducer {
	private Connection conn;
//	private Destination des;
	private Session session;
	private MessageProducer producer;
	
	public JmsProducer(){
		conn = JmsConnection.getInstance().createConnection();
		try {
			conn.start();
			session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
			Destination destination = session.createQueue("books");
			producer = session.createProducer(destination);
		} catch (JMSException e) {
			e.printStackTrace();
		}
		
	}
	
	public void produce(String text){
		TextMessage message;
		try {
			message = session.createTextMessage(text);
			producer.send(message);
		} catch (JMSException e) {
			e.printStackTrace();
		}
		
	}
	
	public void close(){
		try {
			producer.close();
			session.close();
			conn.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	

}
